#include "port_delay.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"
#include <sys/time.h>
#include <unistd.h>

uint32_t get_ms(void)
{
    struct timeval tv_now;
    gettimeofday(&tv_now, NULL);
    uint32_t time_ms = (uint32_t)tv_now.tv_sec * 1000L + (uint32_t)tv_now.tv_usec/1000L;
    return time_ms;
}

uint64_t get_us(void)
{
    struct timeval tv_now;
    gettimeofday(&tv_now, NULL);
    uint64_t time_us = (uint64_t)tv_now.tv_sec * 1000000L + (uint64_t)tv_now.tv_usec;
    return time_us;
}

void delay_ms(uint32_t xms)
{
    vTaskDelay(xms);
}

void delay_us(uint32_t xus)
{
    usleep(xus);
}